package com.expmanage.actions.login;

import java.math.*;

import org.apache.ibatis.session.*;

import com.expmanage.models.*;

import static com.expmanage.actions.utils.DatabaseConfigure.*;

public class sDataObject {

	Student login_student = null;
	
	public boolean checkUser(String u, String p) throws Exception {
		Student newStudent = new Student("", new BigDecimal(u),
				new BigDecimal("1") , p, "");
		SqlSession session = sqlSessionFactory.openSession();
		try {
			StudentMapper mapper = session.getMapper(StudentMapper.class);
			login_student = mapper.selectStudentLogin(newStudent);
			session.commit();
		} catch(Throwable e){
			e.printStackTrace();
			return false;
		}finally {
			session.close();
		}
		if(login_student!=null && login_student.isChecked())
			return true;
		else 
			return false;
	}

	public Student getLogin_student() {
		return login_student;
	}
}
